package xyz.jcat.sca.example.lagou.deliver.web.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.jcat.sca.example.lagou.deliver.SentinelResourceBlockHandler;
import xyz.jcat.common.web.Resp;

@RestController
@RequestMapping("/sentinel")
public class SentinelTestController {

    int i;

    @GetMapping("/demote")
    @SentinelResource(
            value = "sentinel_demote",
            blockHandlerClass = SentinelResourceBlockHandler.class,
            blockHandler = "test"
    )
    public Resp demote() throws InterruptedException {
        if(i++ % 2 == 0) {
            //RT
            Thread.sleep(200);
            //异常比例
            //int j = i/0;
        }
        return Resp.ok("SUCCESS");
    }
}
